import initSidenavList from './components/initSidenavList';
import initNavTabs from './components/initNavTabs';
import initRating from './components/initRating';

import "env-resources-courses.scss";

+function(){
  console.log('resource-courses page loaded');
  
  initSidenavList();
  initNavTabs();
  initRating();
  
  $('.resources-courses-search-input').on('keyup', function(e) {
    const $this = $(this)
    const $btn = $(`#${$this.attr('id').replace('nav-tabs-search-input-', 'nav-tabs-search-button-')}`)
    const disabled = $btn.hasClass('disabled')
    const val = $this.val()
    
    if (val && disabled) {
      $btn.removeClass('disabled')
    } else if (!val && !disabled) {
      $btn.addClass('disabled')
    }
  })
  
  // form submitting
  $('#modal-dialog-add .form-submit')
    .on('click', function(e) {
      e.preventDefault()
      
      console.log('----------- submitting ------------', {
        'modal-dialog-add-level': $('#modal-dialog-add-level').val(),
        'modal-dialog-add-course': $('#modal-dialog-add-course').val(),
        'modal-dialog-add-version': $('#modal-dialog-add-version').val(),
        'modal-dialog-add-book': $('#modal-dialog-add-book').val(),
      })
      
      $('#modal-dialog-add').modal('hide')
    })
    
  $('#modal-dialog-comment .form-submit')
    .on('click', function(e) {
      e.preventDefault()
      
      console.log('----------- submitting ------------', {
        'modal-dialog-comment-rate': $('#modal-dialog-comment-rate').val(),
        'modal-dialog-comment-text': $('#modal-dialog-comment-text').val(),
      })
      
      $('#modal-dialog-comment').modal('hide')
    })
    
  $('#modal-dialog-modify .form-submit')
    .on('click', function(e) {
      e.preventDefault()
      
      console.log('----------- submitting ------------', {
        'modal-dialog-modify-type': $('input[name="modal-dialog-modify-type"]').val(),
      })
      
      $('#modal-dialog-modify').modal('hide')
    })
  
  $('#modal-dialog-delete .form-submit')
    .on('click', function(e) {
      e.preventDefault()
      
      console.log('----------- deleting ------------', {
      })
      
      $('#modal-dialog-delete').modal('hide')
    })
}()